#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <linux/input.h>
#include "log.h"

int g_input;
void InitInput(void)
{
	g_input = open("/dev/input/event0", O_RDONLY | O_NONBLOCK);
	LOG("input open with handle[%d]\n", g_input);
}

void UpdateInput(void)
{
	if (g_input < 0) {
		return;
	}
	int ret = 1;
	while (ret > 0) {
		struct input_event event;
		ret = read(g_input, &event, sizeof(struct input_event));
		if (ret > 0) {
			LOGScroll(0, "touch [%d] [%d:%.03f] type=%d,code=%d,value=%d", ret, 
				event.time.tv_sec % 60, 
				event.time.tv_usec / 1000.0f, 
				event.type, event.code, event.value);
		}
	}
}